package org.example.examsystem.service;


import org.example.examsystem.entity.PjClass;
import org.example.examsystem.mapper.PjClassMapper;
import org.example.examsystem.service.PjClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PjClassServiceImpl implements PjClassService {

    @Autowired
    private PjClassMapper pjClassMapper;

    @Override
    public Page<PjClass> getClasses(Pageable pageable) {
        int offset = (int) pageable.getOffset();
        int limit = pageable.getPageSize();
        List<PjClass> classes = pjClassMapper.getClasses(offset, limit);
        int total = pjClassMapper.getTotalClasses();
        return new PageImpl<>(classes, pageable, total);
    }

    @Override
    public void addClass(PjClass pjClass) {
        pjClassMapper.addClass(pjClass);
    }

    @Override
    public void updateClass(PjClass pjClass) {
        pjClassMapper.updateClass(pjClass);
    }

    @Override
    public void deleteClass(int classid) {
        pjClassMapper.deleteClass(classid);
    }

    @Override
    public List<PjClass> getClassList() {
        return pjClassMapper.getClassList();
    }

    @Override
    public List<PjClass> getAllClasses() {
        return pjClassMapper.getAllClasses();
    }
}
